package com.cedifie.lendapp.ui.user.act

import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.graphics.Color
import android.net.Uri
import android.os.Build
import android.os.CountDownTimer
import android.text.Editable
import android.text.TextWatcher
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.GridLayoutManager
import com.cedifie.lendapp.R
import com.cedifie.lendapp.databinding.ActUserCheckPhoneNumberBinding
import com.cedifie.lendapp.http.HttpHelper
import com.cedifie.lendapp.mvp.MvpAct
import com.cedifie.lendapp.ui.user.adapter.CedUserCheckPhoneNumberTypeAdapter
import com.cedifie.lendapp.ui.user.impl.CedUserCheckPhoneNumberPresenterImpl
import com.cedifie.lendapp.ui.user.view.ICedUserCheckPhoneNumberView
import com.cedifie.lendapp.utils.decoration.GridSpacingItemDecoration
import com.cedifie.lendapp.utils.dialog.SuccessDialog
import com.cedifie.lendapp.utils.event.CedEventManager
import com.cedifie.lendapp.utils.event.CedEventType
import com.cedifie.lendapp.utils.helper.SharedHelper
import com.cedifie.lendapp.utils.receiver.CedSmsBroadcastReceiver
import com.cedifie.lib_baseadapter.CEDOnItemChildClickListener
import com.cedifie.pickerview.builder.TimePickerBuilder
import com.cedifie.pickerview.listener.OnTimeSelectListener
import com.cedifie.pickerview.view.TimePickerView
import com.google.android.gms.auth.api.phone.SmsRetriever
import com.lib.base.utils.DensityUtils
import com.lib.base.utils.TitleBarUtil
import com.lib.base.utils.helper.ActivityStackManager
import com.lib.base.utils.log.LogHelper
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
import org.json.JSONObject
import java.text.SimpleDateFormat
import java.util.Calendar
import java.util.Date

/**
 * Cedifie
 * @Author wwdeng
 * @CreateTime: 2025/4/11 10:41
 * @Annotation：校验手机号
 */

class CedUserCheckPhoneNumberAct: MvpAct<ICedUserCheckPhoneNumberView, CedUserCheckPhoneNumberPresenterImpl>(), ICedUserCheckPhoneNumberView {
    lateinit var binding: ActUserCheckPhoneNumberBinding

    private var sendSuccessDialog: SuccessDialog? = null
    private var smsBroadcastReceiver: CedSmsBroadcastReceiver? = null

    private var checkTypeAdapter: CedUserCheckPhoneNumberTypeAdapter? = null
    private val typeTitleList = arrayListOf(R.string.user_check_phone_number_type_sms,R.string.user_check_phone_number_type_whatsapp,R.string.user_check_phone_number_type_telegram,R.string.user_check_phone_number_type_telegram_bot)
    private var isClickCheck = true

    private val SMS_CONSENT_REQUEST = 200
    var eventRemark = ""

    //等待时长
    private var countdownTimer: MyCountDownTimer? = null
    private var countdown = 60

    //出生日期选择
    private var pvStartDateView: TimePickerView? = null
    companion object {
        fun start(context: Context) {
            //当前栈顶是 手机号校验页面 不重复跳转
            if (ActivityStackManager.isCurrentActivity(CedUserCheckPhoneNumberAct::class.java)){
                return
            }
            val intent = Intent(context, CedUserCheckPhoneNumberAct::class.java)
            context.startActivity(intent)
        }
    }

    override fun getCedRootView(): View {
        binding = ActUserCheckPhoneNumberBinding.inflate(layoutInflater)
        return binding.root
    }

    override fun initCedView() {
        eventRemark = "Check Mobile Page"
        setBackExit(true)
        binding.parentLayout.setPadding(0, TitleBarUtil.getStatusBarHeight(),0,0)
        initCedRefreshLayout()
        initCedCheckPhoneNumberTypeGridView()

        showChcekMobileTypeView(false)
        SmsRetriever.getClient(this).startSmsUserConsent(null)
        registerSMSBroadcastReceiver()
        EventBus.getDefault().register(this)
    }

    override fun initCedListener() {
        //客服
        binding.imgKefu.setOnClickListener {
            onIntent(CedUserFeedbackAct::class.java)
            HttpHelper.addCedEventAction(CedEventType.CLICK.CED_CLICK_CUSTOMER,eventRemark)
        }
        binding.editCode.addTextChangedListener(object : TextWatcher {
            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
            }
            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
            }
            override fun afterTextChanged(s: Editable?) {
                binding.btnSubmit.isEnabled = mvpPresenter.getCheckNumberSelectType().isNotEmpty() && getCedCheckPhoneNumberCode().isNotEmpty()
            }
        })
        binding.editMobile.addTextChangedListener(object : TextWatcher {
            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
            }
            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
            }
            override fun afterTextChanged(s: Editable?) {
                binding.btnConfirm.isEnabled = getCedCheckPhoneNumber().isNotEmpty()
            }
        })

        binding.btnSend.setOnClickListener {
            if (mvpPresenter.getCheckNumberSelectType().isEmpty()){
                return@setOnClickListener
            }
            mvpPresenter?.sendCheckNumberWhatsAppCodeAction()
        }

        binding.imgEdit.setOnClickListener {
            showChcekMobileTypeView(true)
        }
        binding.btnConfirm.setOnClickListener {
            if (getCedCheckPhoneNumber().isEmpty()){
                return@setOnClickListener
            }
            binding.textMobile.text = getCedCheckPhoneNumber()
            showChcekMobileTypeView(false)
        }
        //提交
        binding.btnSubmit.setOnClickListener {
            val checkType = mvpPresenter?.getCheckNumberSelectType()
            if (checkType == "TGBOT"){
                HttpHelper.addCedEventAction(CedEventType.CLICK.CED_CLICK_VERIFICATION_CONTINUE,"${checkType}##${getCedCheckPhoneNumber()}")
                mvpPresenter?.loadCedCheckPhoneNumberTypeTelegramBotLinkAction()
                return@setOnClickListener
            }
            if (getCedCheckPhoneNumber().isEmpty() || getCedCheckPhoneNumberCode().isEmpty()){
                binding.btnSubmit.isEnabled = false
                return@setOnClickListener
            }
            HttpHelper.addCedEventAction(CedEventType.CLICK.CED_CLICK_VERIFICATION_CONTINUE,"${mvpPresenter?.getCheckNumberSelectType()}##${getCedCheckPhoneNumberCode()}##${getCedCheckPhoneNumber()}")
            //立即上报
            CedEventManager.getInstance().updateCedEventsNow()

            mvpPresenter?.onCheckNumberVerificationCodeAction()
        }
    }

    @SuppressLint("SetTextI18n")
    override fun initCedData() {
        val zoneCode = SharedHelper.getCedSPString(SharedHelper.CED_SPKEY.CEDIFIE_TIMEZONE_CODE)
        val mobile = SharedHelper.getCedSPString(SharedHelper.CED_SPKEY.CEDIFIE_MOBILE)
        binding.textZoneCode.text = "+$zoneCode | "
        binding.textMobile.text = mobile
        binding.editMobile.setText(mobile)

        binding.btnSend.text = getString(R.string.user_check_phone_number_code_get)
        binding.btnSend.isEnabled = false
        isClickCheck = true

        val processStr = SharedHelper.getCedSPString(SharedHelper.CED_SPKEY.CEDIFIE_PROCESS)
        if (processStr.isEmpty()){
            //流程信息为空返回刷新信息
            EventBus.getDefault().post(CedEventType.NOTICE.CED_PROCESS_REFRESH)
            finish()
        }
        val data = JSONObject(processStr)
        if (data.optString("smsFlag","") == "YES"){
            val item = JSONObject()
            item.put("checkType","SMS")
            item.put("checkTypeTitle",getString(typeTitleList[0]))
            item.put("isSelected",false)
            checkTypeAdapter?.addLastItem(item)
        }
        if (data.optString("whatsappFlag","") == "YES"){
            val item = JSONObject()
            item.put("checkType","WHATSAPP")
            item.put("checkTypeTitle",getString(typeTitleList[1]))
            item.put("isSelected",false)
            checkTypeAdapter?.addLastItem(item)
        }
        if (data.optString("telegramFlag","") == "YES"){
            val item = JSONObject()
            item.put("checkType","TELEGRAM")
            item.put("checkTypeTitle",getString(typeTitleList[2]))
            item.put("isSelected",false)
            checkTypeAdapter?.addLastItem(item)
        }
        if (data.optString("telegramBotFlag","") == "YES"){
            val item = JSONObject()
            item.put("checkType","TGBOT")
            item.put("checkTypeTitle",getString(typeTitleList[3]))
            item.put("isSelected",false)
            checkTypeAdapter?.addLastItem(item)
        }
        showDefaultCheckTypeView()
    }

    override fun createMvpPresenter(): CedUserCheckPhoneNumberPresenterImpl {
        return CedUserCheckPhoneNumberPresenterImpl(this)
    }

    /* 初始化刷新 */
    private fun initCedRefreshLayout() {
        //禁止加载
        binding.refreshLayout.setEnableLoadMore(false)
        binding.refreshLayout.setEnableAutoLoadMore(false)
        binding.refreshLayout.setOnRefreshListener {
            //发送刷新流程通知
            EventBus.getDefault().post(CedEventType.NOTICE.CED_PROCESS_REFRESH)
        }
        binding.refreshLayout.setOnLoadMoreListener {
            binding.refreshLayout.finishLoadMore()
        }
    }

    @SuppressLint("NotifyDataSetChanged")
    private fun initCedCheckPhoneNumberTypeGridView(){
        binding.typeGridView.setHasFixedSize(true)
        binding.typeGridView.isNestedScrollingEnabled = false
        binding.typeGridView.isFocusableInTouchMode = false //不需要焦点
        binding.typeGridView.layoutManager = GridLayoutManager(this,2)
        checkTypeAdapter = CedUserCheckPhoneNumberTypeAdapter(binding.typeGridView)
        binding.typeGridView.adapter = checkTypeAdapter
        val leftDecoration = DensityUtils.dp2px(12f)
        binding.typeGridView.addItemDecoration(GridSpacingItemDecoration(2, leftDecoration,false))
        binding.typeGridView.itemAnimator = DefaultItemAnimator()
        checkTypeAdapter?.setOnItemChildClickListener(CEDOnItemChildClickListener { _, childView, position ->
            checkTypeAdapter?.let {
                val item = it.getItem(position)
                if (!isClickCheck || item.optBoolean("isSelected") || getCedCheckPhoneNumber().isEmpty()){
                    return@CEDOnItemChildClickListener
                }
                if (childView.id == R.id.tvCheckType){
                    for (i in 0..< it.itemCount){
                        it.getItem(i)?.put("isSelected",false)
                    }
                    item.put("isSelected",true)
                    it.notifyDataSetChanged()
                    binding.textCheckTypeTitle.text = String.format(getString(R.string.user_check_phone_number_type),item.optString("checkTypeTitle"))
                    mvpPresenter?.setCheckNumberType(item.optString("checkType"),true)
                }
            }
        })
    }

    /**
     * 注册SMS广播接收
     */
    private fun registerSMSBroadcastReceiver(){
        // 2 register receiver
        val intentFilter = IntentFilter(SmsRetriever.SMS_RETRIEVED_ACTION)
        smsBroadcastReceiver = CedSmsBroadcastReceiver {
            startActivityForResult(it, SMS_CONSENT_REQUEST)
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
            // Android 13 及以上版本使用 receiverFlags 参数
            registerReceiver(smsBroadcastReceiver, intentFilter, SmsRetriever.SEND_PERMISSION, null, Context.RECEIVER_EXPORTED)// 指定导出标志
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            // Android 8.0 到 Android 12 版本使用带权限的 registerReceiver()
            registerReceiver(smsBroadcastReceiver, intentFilter, SmsRetriever.SEND_PERMISSION, null)
        } else {
            // Android 8.0 以下版本，只使用 receiver 和 intentFilter 参数
            registerReceiver(smsBroadcastReceiver, intentFilter)
        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == SMS_CONSENT_REQUEST) {
            if (resultCode == Activity.RESULT_OK && data != null) {
                // 读取短信内容
                val message = data.getStringExtra(SmsRetriever.EXTRA_SMS_MESSAGE)
                LogHelper.e("Sms content: $message")

                // 提取otp
                val code = extractFirstNumber(message)
                LogHelper.e("Sms code: $code")
                if (code != null){
                    binding.editCode.setText(code)
                }
            } else {
                // 用户不同意或没收到待
                LogHelper.e("User canceled or no message received")
            }
        }
    }

    /**
     * 获取手机号
     */
    override fun getCedCheckPhoneNumber(): String {
        return binding.editMobile.text.toString().trim()
    }

    /**
     * 获取验证码
     */
    override fun getCedCheckPhoneNumberCode(): String {
        return binding.editCode.text.toString().trim()
    }

    /**
     * 切换是否修改手机号View
     */
    private fun showChcekMobileTypeView(isEdit: Boolean){
        //是否允许修改手机号码
        val processStr = SharedHelper.getCedSPString(SharedHelper.CED_SPKEY.CEDIFIE_PROCESS)
        val data = JSONObject(processStr)
        if (data.optString("mobileEditFlag") != "YES"){
            binding.showMobileLayout.visibility = View.VISIBLE
            binding.imgEdit.visibility = View.INVISIBLE
            binding.showEditLayout.visibility = View.GONE
            return
        }
        when(isEdit){
            true -> {
                binding.showMobileLayout.visibility = View.GONE
                binding.showEditLayout.visibility = View.VISIBLE
                onShowSoftInput(binding.editMobile)
                binding.editMobile.setSelection(getCedCheckPhoneNumber().length)
            }
            else -> {
                binding.showMobileLayout.visibility = View.VISIBLE
                binding.imgEdit.visibility = View.VISIBLE
                binding.showEditLayout.visibility = View.GONE
            }
        }
    }

    /**
     * 设置默认选中校验类型
     */
    private fun showDefaultCheckTypeView(){
        //设置默认选中第一个
        checkTypeAdapter?.let {
            if (it.itemCount > 0){
                val item = it.getItem(0)
                item?.put("isSelected",true)
                it.notifyItemChanged(0)
                mvpPresenter?.setCheckNumberType(item.optString("checkType"),false)
                binding.textCheckTypeTitle.text = String.format(getString(R.string.user_check_phone_number_type),item.optString("checkTypeTitle"))
            }
        }
    }

    /**
     * 切换校验类型
     */
    override fun showCedCheckPhoneNumberType(type: String, isSubTrack: Boolean) {
        binding.btnSend.isEnabled = true
        binding.btnSubmit.isEnabled = getCedCheckPhoneNumberCode().isNotEmpty()

        binding.textCheckCodeTitle.visibility = View.VISIBLE
        binding.checkCodeLayout.visibility = View.VISIBLE
        if (type == "TGBOT"){
            binding.textCheckCodeTitle.visibility = View.GONE
            binding.checkCodeLayout.visibility = View.GONE
            binding.btnSubmit.isEnabled = true
        }

        //需要提交埋点
        if (isSubTrack){
            when(type){
                "SMS" -> {
                    HttpHelper.addCedEventAction(CedEventType.CLICK.CED_CLICK_VERIFICATION_SMS,"")
                }
                "WHATSAPP" -> {
                    HttpHelper.addCedEventAction(CedEventType.CLICK.CED_CLICK_VERIFICATION_WHATSAPP,"")
                }
                "TELEGRAM" -> {
                    HttpHelper.addCedEventAction(CedEventType.CLICK.CED_CLICK_VERIFICATION_TELEGRAM,"")
                }
                else -> {
                    HttpHelper.addCedEventAction(CedEventType.CLICK.CED_CLICK_VERIFICATION_TELEGRAM_BOT,"")
                }
            }
        }
    }

    /**
     * 验证码发送成功
     * 当为YES时可以跳过，直接调用流程接口，根据流程步骤whatsappFlag标识走
     */
    override fun showCedCheckPhoneNumberSendCodeSuccess(directLoginFlag: String) {
        hideCedLoading()
        when(directLoginFlag){
            "YES" -> {
                showCedCheckPhoneNumberSuccess()
            }
            else -> {
                startCountdownTimer()
            }
        }
    }

    /**
     * Telegram bot 校验，跳转链接
     */
    override fun showCedCheckPhoneNumberTelegramBotLink(linkUrl: String) {
        val uri = Uri.parse(linkUrl)
        val intent = Intent(Intent.ACTION_VIEW, uri)
        startActivity(intent)
    }

    /**
     * 需要选择出生日期
     */
    override fun showCedCheckPhoneNumberChooseBirthdayDialog() {
        if(pvStartDateView == null){
            //时间可选范围18-100岁
            //当前日期
            val curtDate = Calendar.getInstance()
            val startDate = Calendar.getInstance()
            startDate.timeInMillis = curtDate.timeInMillis
            startDate.add(Calendar.YEAR,-100)

            val endDate = Calendar.getInstance()
            endDate.timeInMillis = curtDate.timeInMillis
            endDate.add(Calendar.YEAR,-18)

            pvStartDateView = TimePickerBuilder(this, object : OnTimeSelectListener {
                override fun onTimeSelect(date: Date?, v: View?) {
                }

                override fun onTimeSelectString(date: Date?, showDate: String?) {
                    val value = SimpleDateFormat("yyyy-MM-dd").format(date)
                    mvpPresenter?.onCheckNumberVerificationCodeAction(value)
                }
            })
                .setDate(endDate) //默认选中
                .setRangDate(startDate, endDate) //可选择时间范围
                .setLayoutRes(R.layout.dialog_birth) { v ->
                    val ivClose = v?.findViewById<ImageView>(R.id.ivClose)
                    ivClose?.setOnClickListener {
                        pvStartDateView?.dismiss()
                    }
                    //确定
                    val btnDone = v?.findViewById<TextView>(R.id.btnDone)
                    btnDone?.setOnClickListener {
                        pvStartDateView?.returnData()
                        pvStartDateView?.dismiss()
                    }
                }
                .isDialog(true)
                .setContentTextSize(16)
                .setType(booleanArrayOf(true, true, true, false, false, false))
                .setLabel("", "", "", "", "", "")
                .setLineSpacingMultiplier(3f)
                .setTextXOffset(40, 40, 40, 40, 40, 40)
                .isCenterLabel(false)//是否只显示中间选中项的label文字，false则每项item全部都带有label。
                .setTextColorCenter(Color.parseColor("#FF08252C")) //设置选中项文字颜色
                .setTextColorOut(Color.parseColor("#FF9CA8AB"))//默认颜色
                .setContentTextSize(16)
                .isAlphaGradient(true)
                .setItemVisibleCount(3)
                .isCyclic(true)
                .setDividerColor(ContextCompat.getColor(this, R.color.transparent))
                .build()
            val dialog = pvStartDateView?.dialog
            if (dialog != null){
                val params = FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER)
                params.leftMargin = 0
                params.rightMargin = 0
                pvStartDateView?.dialogContainerLayout?.setLayoutParams(params)
                val dialogWindow = dialog.window
                if (dialogWindow != null) {
                    dialogWindow.setWindowAnimations(com.cedifie.pickerview.R.style.picker_view_scale_anim) //修改动画样式
                    dialogWindow.setGravity(Gravity.CENTER)
                    dialogWindow.setDimAmount(0.3f)
                }
            }
        }
        pvStartDateView?.show()
    }

    /**
     * 校验成功
     */
    override fun showCedCheckPhoneNumberSuccess() {
        SharedHelper.saveCedSPData(SharedHelper.CED_SPKEY.CEDIFIE_MOBILE,getCedCheckPhoneNumber())
        //发送刷新流程通知
        EventBus.getDefault().post(CedEventType.NOTICE.CED_PROCESS_REFRESH)
        if (countdownTimer != null){
            countdownTimer?.cancel()
        }
        finish()
    }

    /**
     * 发送成功提示
     */
    private fun showSendCodeSuccessDialog(){
        if (sendSuccessDialog == null){
            sendSuccessDialog = SuccessDialog(this)
            sendSuccessDialog?.setCancelable(false)
            sendSuccessDialog?.setCanceledOnTouchOutside(false)
        }
        sendSuccessDialog?.show()
        launch(Dispatchers.Main){
            delay(1500)
            sendSuccessDialog?.dismiss()
        }
    }

    /**
     * 提取连续的数字
     */
    private fun extractFirstNumber(input: String?): String? {
        if(input.isNullOrBlank()) return ""

        val regex = "\\d+".toRegex()
        return regex.find(input)?.value
    }

    class MyCountDownTimer(private val act: CedUserCheckPhoneNumberAct, millisInFuture: Int, countDownInterval: Long): CountDownTimer(millisInFuture.toLong(), countDownInterval) {
        override fun onTick(millisUntilFinished: Long) {
            // 这里每隔一段时间（定时器间隔）会被调用
            // 可以在这里更新UI，显示剩余时间
            act.countdown = (millisUntilFinished / 1000).toInt()
            act.showCheckCountdownText()
        }
        override fun onFinish() {
            // 倒计时完成时被调用
            act.showCheckCountdownComplete()
        }
    }

    /**
     * 倒计时
     */
    @SuppressLint("SetTextI18n")
    private fun showCheckCountdownText(){
        binding.btnSend.text = "$countdown S"
    }

    /**
     * 倒计时完成
     */
    private fun showCheckCountdownComplete(){
        countdown = 60
        binding.btnSend.text = getString(R.string.user_check_phone_number_code_resend)
        binding.btnSend.isEnabled = true
        isClickCheck = true
        showChcekMobileTypeView(false)
    }

    /**
     * 启动倒计时
     */
    @SuppressLint("SetTextI18n")
    private fun startCountdownTimer() {
        showSendCodeSuccessDialog()
        //随机 60秒 等待时长
        countdown = 60
        binding.btnSend.text = "$countdown S"
        binding.btnSend.isEnabled = false
        isClickCheck = false
        //手机号码输入框变成不可编辑状态
        binding.showMobileLayout.visibility = View.VISIBLE
        binding.imgEdit.visibility = View.INVISIBLE
        binding.showEditLayout.visibility = View.GONE

        if (countdownTimer == null){
            countdownTimer = MyCountDownTimer(this, countdown * 1000, 1000)
        }
        countdownTimer?.start()
    }

    /**
     * 更新总流程完成
     */
    @Subscribe(threadMode = ThreadMode.POSTING)
    public fun onRefreshProcessCompleted(event: String){
        LogHelper.e("process refresh success >>>>>>>>>>")
        when(event){
            CedEventType.NOTICE.CED_PROCESS_REFRESHED -> {//总流程刷新完成
                hideCedLoading()
                val processStr = SharedHelper.getCedSPString(SharedHelper.CED_SPKEY.CEDIFIE_PROCESS)
                val obj = JSONObject(processStr)
                val smsFlag = obj.optString("smsFlag","")
                val whatsappFlag = obj.optString("whatsappFlag","")
                val telegramFlag = obj.optString("telegramFlag","")
                val telegramBotFlag = obj.optString("telegramBotFlag","")
                //需要校验手机号
                if ("YES" == smsFlag || "YES" == whatsappFlag || "YES" == telegramFlag || "YES" == telegramBotFlag){
                    return
                }
                //校验成功
                showCedCheckPhoneNumberSuccess()
            }
        }
    }

    override fun hideCedLoading() {
        super.hideCedLoading()
        binding.refreshLayout.finishRefresh()
    }

    override fun onStart() {
        super.onStart()
        HttpHelper.addCedEventAction(CedEventType.PAGE.CED_PAGE_VERIFICATION_SMS_START,eventRemark)
        val checkType = mvpPresenter?.getCheckNumberSelectType()
        if (checkType == "TGBOT"){
            //需要调流程接口查询校验结果
            EventBus.getDefault().post(CedEventType.NOTICE.CED_PROCESS_REFRESH)
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        HttpHelper.addCedEventAction(CedEventType.PAGE.CED_PAGE_VERIFICATION_SMS_END,eventRemark)
        EventBus.getDefault().unregister(this)
        if (countdownTimer != null){
            countdownTimer?.cancel()
            countdownTimer = null
        }
        if (smsBroadcastReceiver != null){
            unregisterReceiver(smsBroadcastReceiver)
        }
    }
}